package com.example.demosecurity.common.security;

import com.example.demosecurity.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

/**
 * 自定义登录认证
 */
@Service
public class CustomUserDetailsService implements UserDetailsService {

    private UserMapper userMapper;

    @Autowired
    public UserMapper userMapper(UserMapper userMapper) {
        return this.userMapper = userMapper;
    }

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        return userMapper.getUser(username);
    }
}
